package cn.springcloud.fix.demo.proxy.jdk;

import cn.springcloud.fix.demo.proxy.Person;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

public class MeiPo implements InvocationHandler {

    private Person target;

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        System.out.println("------------");
        System.out.println("我是媒婆，要不要替你找对象");
        Object result = method.invoke(target, args);
        System.out.println("------------");
        System.out.println("好的，我这就去找");
        return result;
    }

    public Object getProxy(Person target) {
        this.target = target;
        // return Proxy.newProxyInstance(target.getClass().getClassLoader(), target.getClass().getInterfaces(), this);
        return Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(), this.target.getClass().getInterfaces(), this);
    }
}
